package com.honkentuber;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.json.simple.JSONObject;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MyUser {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;

  // @Unique
  @Persistent
  private String userId;

  @Persistent
  private String nickName;

  @Persistent
  private String email;

  public MyUser(User user) {
    userId = user.getUserId();
    nickName = user.getNickname();
    email = user.getEmail();
  }

  public Key getKey() {
    return key;
  }

  public String getUserId() {
    return userId;
  }

  public String getNickName() {
    return nickName;
  }

  public String getEmail() {
    return email;
  }

  public String toString() {
    return userId + "|" + nickName;
  }

  @SuppressWarnings("unchecked")
  public JSONObject toJson() {
    JSONObject jsonRoom = new JSONObject();
    jsonRoom.put("key", KeyFactory.keyToString(key));
    jsonRoom.put("nickName", nickName);
    jsonRoom.put("email", email);
    return jsonRoom;
  }
}